package com.example.controller;

import com.alipay.api.AlipayApiException;
import com.example.service.PayService;
import com.example.vo.AliPay;
import com.example.vo.AliPaySync;
import com.example.vo.Result;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


@RestController
@Slf4j
public class PayController {

    @Resource
    private PayService payService;

    /**
     * 阿里支付
     * @param alipay
     * @return
     * @throws AlipayApiException
     */
    @RequestMapping("/alipay")
    public Result alipay(@RequestBody AliPay alipay) throws AlipayApiException {
        String str = payService.aliPay(alipay);
        return Result.ok(str);

        //这里Result是自定义的，用于携带消息返回前端，也可以直接用map
    }

    @PostMapping("/alipayAsyncHandle")
    @ResponseBody
    public String AliPayAsyncHandle(AliPaySync aliPaySync, HttpServletRequest request) throws AlipayApiException {
        System.out.println("=========支付宝异步回调========");
        return payService.AliPayAsyncHandle(aliPaySync,request);

    }

}
